package org.openmore.consumer.service.feign;

import io.swagger.annotations.ApiParam;
import org.openmore.consumer.dto.common.BaseResponse;
import org.openmore.consumer.dto.common.RoleDto;
import org.openmore.consumer.dto.common.StringParams;
import org.openmore.consumer.service.feignImpl.RoleServiceImpl;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

@Service
@FeignClient(value = "openmore-opc", fallbackFactory = RoleServiceImpl.class)
public interface RoleService {

    /**查询角色列表*/
    @RequestMapping(method = RequestMethod.GET, value = "/api/role/query")
    public BaseResponse selectAllByPage(
            @RequestParam(required = false, defaultValue = "") @ApiParam(value = "角色名") String name,
            @RequestParam(required = false, defaultValue = "0") @ApiParam(value = "分页第几页") Integer pageNum,
            @RequestParam(required = false, defaultValue = "0") @ApiParam(value = "每页多少记录") Integer pageSize);

    /**查询角色对应权限*/
    @RequestMapping(method = RequestMethod.POST, value = "/api/role/{id}/permission")
    public BaseResponse grantPermission(
            @PathVariable @ApiParam(value = "角色id") String id,
            @RequestBody @ApiParam(value = "权限列表字符串，以逗号间隔") StringParams param);

    /**根据查询角色信息*/
    @RequestMapping(method = RequestMethod.GET, value = "/api/role/{id}")
    public BaseResponse getRoleById(@PathVariable @ApiParam(required = true, value = "id") String id);

    /**更新角色信息*/
    @RequestMapping(method = RequestMethod.PUT, value = "/api/role")
    public BaseResponse updateRole(@RequestBody @ApiParam(value = "新信息", required = true) RoleDto role);

    /**创建新角色*/
    @RequestMapping(method = RequestMethod.POST, value = "/api/role", consumes = {APPLICATION_JSON_UTF8_VALUE})
    public BaseResponse insertRole(@RequestBody @ApiParam(value = "创建", required = true) RoleDto role);

    /**删除角色信息*/
    @RequestMapping(method = RequestMethod.DELETE, value = "/api/role/{id}")
    public BaseResponse deleteRole(@PathVariable @ApiParam(value = "id", required = true) String id);

}
